﻿@model Inscriptionem.Models.Blog.Views.Controls.ArchiveMenuViewModel
           
@{
    var month = new Dictionary<int, string>()
    {
        {1, "January"},
        {2, "February"},
        {3, "March"},
        {4, "April"},
        {5, "May"},
        {6, "June"},
        {7, "July"},
        {8, "August"},
        {9, "September"},
        {10, "October"},
        {11, "November"},
        {12, "December"}
    };

    var maximumAvailableYear = Model.ArchiveKeys.Max(k => k / 100);
    var availableYears = Model.ArchiveKeys.Select(k => k / 100).Distinct().OrderByDescending(y => y);
}

@foreach (var year in availableYears)
{
    <a onclick="toggleArchive(@year);">Archive for @year year</a>
    <hr style="margin-bottom:0px;" />
    <ul id="archive-@year" style="margin-left: 10px; margin-bottom: 10px; @(year < maximumAvailableYear - 2 ? "display:none;" : string.Empty)">
        @foreach (var key in Model.ArchiveKeys.Where(k => k / 100 == year).OrderByDescending(k => k))
        {
            var title = string.Format("{0} {1}", month[key % 100], year);
            <text>
                <li class="cat-item">
                    <a href="/@Model.Language/@Model.Section/Archive/@key" title="@title">@title</a>
                </li>
            </text>
        }
    </ul>
}


<script>
    function toggleArchive(year) {
        var element = document.getElementById("archive-" + year);

        if (element.style.display != "none") {
            element.style.display = "none";
        } else {
            element.style.display = "block";
        }
    }
</script>